package com.zzq.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zzq.constant.MessageConstant;
import com.zzq.entity.PageResult;
import com.zzq.entity.QueryPageBean;
import com.zzq.entity.Result;
import com.zzq.pojo.Address;
import com.zzq.service.AddressService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 幼儿猿大班
 * 2021/7/30
 */
@RestController
@RequestMapping("/address")
public class AddressController {

    @Reference
    private AddressService addressService;
    @RequestMapping("/findPage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
            return addressService.findPage(queryPageBean);
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        try {
            addressService.deleteById(id);
            return new Result(true,"删除地址成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(true,"删除地址失败");
        }
    }

    @RequestMapping("/addAddress")
    public Result addAddress(@RequestBody Map<String,Object> map){
        try {
            addressService.address(map);
            return new Result(true,"地址添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"地址添加失败");
        }
    }

    @RequestMapping("/findAllMaps")
    public Map findAllMaps() {

        Map<String, Object> hashMap= addressService.findMaps();

        return hashMap;

    }
}
